<?php
session_start();
require '../common/Utility.php';
require '../crud/CustomSecurity.class.php';
require '../crud/Categs_smetki.class.php';
require '../crud/Tsmetki.class.php';
require '../db/configuration.php';
loginCheck();

//pre_dump($_POST);
//echo '<script language="javascript" type="text/javascript" defer> alert('.$_POST["descr_id"].');</script>';
$smetki = new Tsmetki(con());
if (isset($_POST['date_id'])){
	$smetki->update($_POST['date_id'], 'date', $_POST['newvalue']);
	echo $_POST['newvalue'];
	echo '<script language="javascript" type="text/javascript" defer> refreshForced();</script>';
} else if (isset($_POST['descr_id'])){
	$smetki->update($_POST['descr_id'], 's_descr', $_POST['newvalue']);
	echo $_POST['newvalue'];
} else if (isset($_POST['comment_id'])){
	$smetki->update($_POST['comment_id'], 'comment', $_POST['newvalue']);
	echo $_POST['newvalue'];
} else if (isset($_POST['sum_id'])){
	$smetki->update($_POST['sum_id'], 'sum', $_POST['newvalue']);
	echo $_POST['newvalue'];
} else if (isset($_POST['type_id'])){
	$smetki->update($_POST['type_id'], 'vid', $_POST['newvalue']);
	if($_POST['newvalue'] == 0){
		echo 'разход';	
	} else if($_POST['newvalue'] == 2){
		echo 'изтеглени';
	} else {
		echo 'приход';
	}
} else if (isset($_POST['categ_id'])){
	$smetki->update($_POST['categ_id'], 'categ', $_POST['newvalue']);
	$cat_smetki = new Categs_smetki(con());
	$categories = $cat_smetki->getAll();
	echo getCategoryValue($categories, $_POST['newvalue']);
}

function getCategoryValue($categories, $index){
	foreach($categories as $line){
		if ($line[0] == $index){
			return $line[1];
		}
	}
}



?>